﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;

namespace entgpguayas.Code
{
    public class ValidateFiles
    {
          private bool _IsImage = false;
          private bool _IsOfficeDocument = false;
          private bool _ValidFileSize = false;
          private bool _ValidImageDimension =  false;
          private string _FileType = string.Empty;
          private int _FileSize = 0;
          private int _MaxWidth = 600;
          private int _MaxHeight = 600;

        

          public bool IsImage
          {
           get
           {
            return _IsImage;
           }
           set
           {
            _IsImage = value;
           }
          }
 
      public bool ValidFileSize
          {
           get
           {
            return _ValidFileSize;
           }
           set
           {
            _ValidFileSize = value;
           }
          }
 
      public string FileType
      {
           get
           {
            return _FileType;
           }
           set
           {
            _FileType = value;
           }
      }
 
      public bool ValidImageDimension
      {
           get
           {
            return _ValidImageDimension;
           }
           set
           {
            _ValidImageDimension = value;
           }
      }
 
      public ValidateFiles()
      {
           // Default construcor
      }
 
      public bool ValidateFileIsImage(string fileType)
      {
           this._FileType = fileType;
           switch (fileType)
           {
             case "image/gif":
             case "image/jpeg":
             case "image/pjpeg":
             case "image/png":
             IsImage = true;
             break;
             default:
             IsImage = false;
             break;
            }
             return IsImage;
      }

      public void SetUserImageSize(int maxW, int maxH)
      {
              _MaxWidth = maxW;
              _MaxHeight = maxH;
      }
      public bool ValidateUserImageSize(int maxFileSize, int fileSize)
      {
            this._FileSize = fileSize;
            if (maxFileSize > fileSize)
            return ValidFileSize = true;
            return ValidFileSize;
      }
 
      public bool ValidateUserImageDimensions(HttpPostedFile file)
      {
           using (Bitmap bitmap = new Bitmap(file.InputStream, false))
           {
            if (bitmap.Width < _MaxWidth && bitmap.Height < _MaxHeight)
            _ValidImageDimension = true;
            return ValidImageDimension;
           }
      }
 
    }
}